<template>
	<!--品牌管理 -->
	<view class="page-content">
		<!--列表-->
		<scroll-view class="page-body" :scroll-top="scrollTop" scroll-y="true" @scrolltolower="loadmore()">
			<template v-if="datalist && datalist.length > 0 ">
				<block v-for="(item,index) in datalist" :key="index">
					<view class="box-li">
						<view class="box-li-l">
							<image class="logo" :src="item.logo_img"></image>
							<view class="name">{{item.title}}
								<view class="name-txt" @click.stop="toauth(item.id,item.auth)"
									:style="{background:item.auth===1?'#198FFF':'#eee',color:item.auth===1?'#fff':'#999'}">{{item.auth===1?'已认证':'未认证'}}</view>
							</view>
						</view>
						<view class="box-li-r">
							<image class="icon-tb" @click="toEdit('edit',item.id,item.title,item.logo_img)" src="/static/icon/icon-bianji.png"></image>
							<image class="icon-tb" @click="toDelete(item.id)" :src="$mAssetsPath.icon_shanchu"></image>
						</view>
					</view>
				</block>
				<!-- 上拉加载 -->
				<view class="det-con-more">
					<load-more :loadmore="load_more1"></load-more>
				</view>
			</template>
			<!--无数据-->
			<empty v-else no-full type="noData"></empty>
		</scroll-view>
		<!--编辑框-->
		<w-popup :show="showtip" :type="type1" @change="change1">
			<view class="w-tip">
				<!-- <view class="w-tit">解散团队</view> -->
				<view class="w-con">
					<view class="txt-row">是否确认删除？</view>
				</view>
				<view class="w-but">
					<view class="w-but-txt" @click="cancel('tip')">取消</view>
					<view class="w-but-txt" @click="confirm">确认</view>
				</view>
			</view>
		</w-popup>
	</view>
</template>

<script>
	import wPopup from '@/components/w-popup/w-popup2.vue';// 弹窗
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	import {
		getCompanyLists,delCompanys
	} from '@/common/api.js';
	import store from '@/store'
	import wTit from '@/components/w-tit/w-tit-back.vue';
	import loadMore from '@/components/uni-load-more/load-more.vue';
	export default {
		components: {
			wTit,loadMore
		},
		data() {
			return {
				showtip: false, //是否显示弹窗2
				content1: '顶部弹 popup',
				type1: '', //弹窗显示方式
				scrollTop: 0,
				noData: false,
				load_more1: '', //下拉加载文字
				load_sta: false, //是否是加载状态
				datalist: [],
				formData:{
					page:1,
					limt:10
				},
				sel_id: 0,
			}
		},
		computed: {
		},
		onShow(option) {
			this.getdata();
		},
		onLoad(query) {
			console.log(222)
		},
		onNavigationBarButtonTap(e) {
			console.log(23,e)
			if (e.index == 0) {
				uni.navigateTo({
					url: `/pages/brandCreation/brand?type=add&pageType=1`,
				})
			}
		},
		methods: {
			...mapActions('user', ['setToken']),
			//下拉加载
			loadmore() {
				console.log('下拉加载');
				let _self = this;
				_self.load_sta = true;
				_self.formData.page++;
				_self.getdata(_self.formData);
			},
			//跳转认证
			toauth(id,auth){
				if(auth===2){
					uni.navigateTo({
						url:`/pages/brandCreation/authentication?id=${id}&auth=${auth}&type=add`
					})
				}else{
					uni.navigateTo({
						url:`/pages/brandCreation/authentication?id=${id}&auth=${auth}&type=edit`
					})
					uni.showToast({
						title:'功能待完善！',
						icon:'none',
						duration:2000
					})
				}
			},
			//弹窗确认
			confirm(){
				delCompanys({id:this.sel_id}).then(res=>{
					console.log(1,res)
					if (res.code === 2000) {
						uni.showToast({
							title: '删除成功！',
							icon: 'none',
							duration: 2000
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						})
					}
					this.showtip = false;
					this.getdata();
				})
			},
			//接口-获取列表数据
			getdata(){
				getCompanyLists(this.formData).then(res=>{
					if(res.code === 2000){
						this.datalist = res.data.data;
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none',
							duration:2000
						})
					}
				})
			},
			//跳转编辑
			toEdit(type,id,title,logo_img) {
				uni.navigateTo({
					url: `/pages/brandCreation/brand?pageType=1&type=${type}&id=${id}&title=${title}&logo_img=${logo_img}`
				})
			},
			//删除
			toDelete(id) {
				this.showtip = true;
				this.content1 = 'center';
				this.type1 = 'center';
				this.sel_id = id;
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			//取消
			cancel(){
				this.show = false
				this.showtip = false
			},
			change1(e) {
				if (!e.show) {
					this.showtip = false
				}
			},
		}
	}
</script>

<style lang="scss">
	/* 提示窗口 */
	.w-tip {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		width: 70vw;
		border-radius: 10rpx;
		background-color: #fff;
		box-shadow: 0rpx 7rpx 7rpx 0rpx rgba(0, 0, 0, 0.1);
		margin: 30rpx auto 0;
	
		.w-tit {
			font-size: 36rpx;
			font-weight: bold;
			color: $font-color-3;
			line-height: 60rpx;
			height: 60rpx;
			margin-top: 20rpx;
			text-align: center;
		}
	
		.w-but {
			display: flex;
			font-size: 32rpx;
			font-weight: 400;
			color: $font-color-b3;
			height: 84rpx;
			line-height: 84rpx;
	
			.w-but-txt {
				flex: 1;
				text-align: center;
				border-right: 1rpx solid #f5f5f5;
			}
	
			.w-but-txt:last-of-type {
				border-right: none;
			}
		}
	
		.w-con {
			display: flex;
			text-align: center;
			font-weight: 400;
			padding: 60rpx 30rpx;
			border-bottom: 1rpx solid #f5f5f5;
			.txt-row{
				width: 100%;
				text-align: center;
				font-size: 28rpx;
				color: $font-color-9;
			}
		}
	}
	.titleNview-placing {
		height: var(--status-bar-height);
		box-sizing: content-box;
		background: $uni-bg-color;
		display: block;
		position: sticky;
		top: 0rpx;
		z-index: 9999;
		overflow: hidden
	}

	.det-con-more {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-bottom: 10rpx;
		color: #bbb;
		font-size: 24rpx;
	}

	.icon-tb {
		width: 36rpx;
		height: 36rpx;
		margin-left: 40rpx;
	}

	.page-content {
		display: flex;
		flex-direction: column;
		background: $uni-bg-color;
		width: 100vw;
		height: 100%;
		border-top: 1rpx solid #f5f5f5;

		.page-body {
			height: 100%;
			display: flex;
			flex-direction: column;
			padding-top: 30rpx;

			.box-li {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 30rpx;
				border-bottom: 1rpx solid #f5f5f5;
				padding: 0 30rpx 30rpx 30rpx;
				.box-li-r{
					display: flex;
					align-items: center;
				}

				.box-li-l {
					display: flex;

					.logo {
						width: 40rpx;
						height: 40rpx;
						margin-right: 20rpx;
					}

					.name {
						display: flex;
						align-items: center;
						font-size: 32rpx;
						font-weight: 400;
						color: $uni-text-color;

						.name-txt {
							height: 40rpx;
							line-height: 40rpx;
							padding: 0 10rpx;
							border-radius: 4rpx;
							margin-left: 20rpx;
							font-size: 20rpx;
						}
					}
				}
			}
		}
	}
</style>
